<?php
#set_include_path(get_include_path() . PATH_SEPARATOR . '/home/animeshs/public_html/public-html-ani/nitrogen-tank/google-api-php-client/src/');
#require_once '/home/animeshs/public_html/public-html-ani/nitrogen-tank/google-api-php-client/src/Google/autoload.php'; // or wherever autoload.php is located
#$client = new Google_Client();
$keyid="AIzaSyCu8qmBi8gRZh1EvnTdAahg8eWdoQG1Nus";
$docid="1U_BJ6XlyY_dC8rN8LHkPRROmOkZ82f3Nhizyi4o2";
#$client->setDeveloperKey($keyid);
#$service = new Google_Service_Books($client);
#$fileget="https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%201U_BJ6XlyY_dC8rN8LHkPRROmOkZ82f3Nhizyi4o2&key=AIzaSyCu8qmBi8gRZh1EvnTdAahg8eWdoQG1Nus";
echo "<form method=post name=f1 action='input.php'>";
echo "<select name='tank'>";
$range = range(1,3);
foreach ($range as $tank) {
	if($tank==$_POST['tank']){ echo "<option value='$tank' selected>$tank Tank</option>";}
else{ echo "<option value='$tank'>$tank Tank</option>";}
}
echo "</select>";

echo "<select name='rack'>";
$range = range(1,6);
foreach ($range as $rack) {
	if($rack==$_POST['rack']){ echo "<option value='$rack' selected>$rack Rack</option>";}

else{  echo "<option value='$rack'>$rack Rack</option>";}
}
echo "</select>";

echo "<select name='box'>";
$range = range(1,10);
foreach ($range as $box) {
	if($box==$_POST['box']){ echo "<option value='$box' selected>$box Box</option>";}
  else{echo "<option value='$box'>$box Box</option>";}
}
echo "</select>";

echo "<select name='num'>";
$range = range(1,100);
foreach ($range as $num) {
	if($num==$_POST['num']){ echo "<option value='$num' selected>$num Number</option>";}
else{ echo "<option value='$num'>$num Number</option>"; }
}
echo "</select>";
echo "<input type=submit value=Submit>";
echo "</form>";
$num=$_POST['num'];
$box=$_POST['box'];
$rack=$_POST['rack'];
$tank=$_POST['tank'];

echo "Selected Tank-$tank Rack-$rack Box-$box,Number-$num<br>";
$id=$num+100*($box-1)+(($rack-1)*10*100)+(($tank-1)*6*10*100);
#$tank=1;
#$rack=1;
#$box=1;
#$num=3;
$rowid=$id+1;
$fileget="https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20ROWID%20FROM%20".$docid."%20WHERE%20RowNum=%27".$id."%27&key=".$keyid;
$json_string =    file_get_contents($fileget);
$parsed_json = json_decode($json_string);
foreach($parsed_json->columns as $value) {
	echo $value,"\t";
}
echo "<br /> \n";

foreach($parsed_json->rows as $value) {
	foreach($value as $value2) {
		echo $value2,"\t";
	}
	echo "<br /> \n";
}
$rowid=$value2;
#echo $rowid;
#$fileset="https://www.googleapis.com/fusiontables/v1/query?sql=UPDATE%201U_BJ6XlyY_dC8rN8LHkPRROmOkZ82f3Nhizyi4o2%20SET%20CellLine=%27test%27%20WHERE%20ROWID=%27".$rowid."%27&key=".$keyid;
$squery="UPDATE $docid SET CellLine = 'RP8226' WHERE ROWID = '".$rowid."'";
#$squery="UPDATE $docid SET CellLine = 'teat' WHERE ROWID = '2'";#.$rowid."'";
$url="https://www.googleapis.com/fusiontables/v2/query";
$data=http_build_query(array('sql' => $squery));
$options = array(
    'http' => array(
        'method'  => 'POST',
        'content' => $data,
	'header' => array('Authorization: Bearer ya29.hgGPy5UgKMjmQtrl_6tt5RQpIvsmab7rjzcJwGj1O2wdw8RE-m3crRKOwCLbwInFDCDXw9TRCOrCDQ','Content-type: application/x-www-form-urlencoded')
    )
);
$context  = stream_context_create($options);
echo "Contect:",$context,$data;
$result = file_get_contents($url, false, $context);
var_dump($result);
?>

